# 项目：py-advance
# 文件：05-多图组合
# 作者：Frank Gong
# 日期：2025/3/13 15:00
# coding:utf-8


from pyecharts.charts import Bar,Line,Grid
from pyecharts  import options
from pyecharts.options import GridOpts

# 1.准备数据
cate = ['西安','咸阳','宝鸡','渭南','延安','商洛']
data1 = [15000,7000,5500,4900,8000,10800]
data2 = [8000,5200,4000,3800,3000,7900]
# 2.创建图表对象
bar = Bar()
line = Line()
# 3.关联数据
bar.add_xaxis(cate)
bar.add_yaxis("GDP",data1)
line.add_xaxis(cate)
line.add_yaxis("CPI",data2)

grid = Grid()

# 网页标题
bar.page_title="陕西省GDP&CPI对比图"
# 图表标题title_opts
# 图表工具箱toolbox_opts
bar.set_global_opts(title_opts=options.TitleOpts(title='陕西省GDP和CPI指数对比图',subtitle='2024年全年'),
                    toolbox_opts=options.ToolboxOpts())
grid.add(bar,grid_opts={'bottom':'60%'})
grid.add(line,grid_opts={'top':'60%'})

# 4.渲染到html
grid.render('../files/组合图.html')